﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Collections.Generic;

namespace ManPowerEngine
{
	/// <summary>
	/// Sound System of MPE
	/// </summary>
	public class SoundSystem
	{
		private static SoundSystem msSoundSystem;
		private static Dictionary<string, Sound> msSounds;
		internal SoundSystem()
		{
			msSoundSystem = this;
			msSounds = new Dictionary<string, Sound>();
		}

		/// <summary>
		/// get Sounds library
		/// </summary>
		public static Dictionary<string, Sound> Sounds
		{
			get { return msSounds; }
		}

		/// <summary>
		/// Add a new sound into sound system
		/// </summary>
		/// <param name="key">The string used to access this sound</param>
		/// <param name="uri">The URI of this sound</param>
		/// <param name="loop">Is this a loop sound?</param>
		/// <param name="autoplay">Start to play after the sound is downloaded?</param>
		/// <returns>The new sound object</returns>
		public static Sound Add(string key, string uri, bool loop, bool autoplay)
		{
			if (msSounds.ContainsKey(key))
			{
				throw new ManPowerException("Sound already existing: " + key);
			}
			Sound newsound = new Sound(uri, loop, autoplay);
			msSounds.Add(key, newsound);
			return newsound;
		}

		/// <summary>
		/// Remove a sound from sound system
		/// </summary>
		/// <param name="key">The key of the sound you are going to remove</param>
		public static void Remove(string key)
		{
			Sound sound = msSounds[key];
			if (sound != null)
			{
				sound.CleanUp();
				msSounds.Remove(key);
			}
		}
	}
}
